
<?php
class Sys_Tianrun {
	var $base_url = "http://api.clink.cn";
	var $enterpriseId = "3005636";
	var $admin_name = "admin";
	var $admin_pwd = "XZfHVuEj";
	
	function CreateUser($create_num)
	{
		$result = array();
		
		$pwd_md5 = md5($this->admin_pwd);
		
		$maozhua_wb = Zend_Registry::get('maozhua_wb');
		$select = $maozhua_wb->select();
		$select->from("params", array("pval"));
		$select->where("pkey = ?", "current_user_id");

		$row = $maozhua_wb->fetchRow($select);
		
		$current_user_id = $row['pval'];
		
		$areaCode = "010";
		
		$pwd_pre = "URUYHGJH2389u8u";
		
		$mod_ext = new Sys_Extensions();
		
		$data_array = array();
		
		for($n=0;$n<$create_num;$n++)
		{
			$current_user_id += 1;
			
			$pwd = substr(sha1($pwd_pre.$current_user_id), 0, 10);
			
			$url = $this->base_url."/interfaceAction/clientInterface!save.action?enterpriseId=".$this->enterpriseId."&userName=".$this->admin_name."&password=".$pwd_md5."&cno=".$current_user_id."&name=".$current_user_id."&areaCode=".$areaCode."&pwd=".$pwd."&skillIds=23602&skillLevels=1";
			
			$fb = $mod_ext->Broadcast($url, $data_array, 1, 0);
			
			if('success' == $fb['result'])
			{
				$result[] = $current_user_id;
			}
		}
		
		$set = array("pval" => $current_user_id);
		$where = "pkey='current_user_id'";
		$maozhua_wb->update("params", $set, $where);
		
		return $result;
	}
	
	function UpdateCallPhone($cno, $call_phone)
	{
		$seed = mt_rand(1000, 9999);
		$pwd_md5 = md5(md5($this->admin_pwd).$seed);
		
		$data_array = array();
		
		$url = $this->base_url."/interface/client/ChangeBindTel?enterpriseId=".$this->enterpriseId."&userName=".$this->admin_name."&pwd=".$pwd_md5."&seed=".$seed."&cno=".$cno."&bindTel=".$call_phone;
		
		$mod_ext = new Sys_Extensions();
		$fb = $mod_ext->Broadcast($url, $data_array, 1, 0);
		
		return $fb;
	}
	
	function ClientOnline($call_id, $status, $bindTel, $type)
	{
		$seed = mt_rand(1000, 9999);
		$pwd_md5 = md5(md5($this->admin_pwd).$seed);
		
		$data_array = array();
		
		$url = $this->base_url."/interface/client/ClientOnline?enterpriseId=".$this->enterpriseId."&userName=".$this->admin_name."&pwd=".$pwd_md5."&seed=".$seed."&cno=".$call_id."&status=".$status."&bindTel=".$bindTel."&type=".$type;
		
		$mod_ext = new Sys_Extensions();
		$fb = $mod_ext->Broadcast($url, $data_array, 1, 0);
		
		return $fb;
	}
	
	function ClientOffline($call_id)
	{
		$seed = mt_rand(1000, 9999);
		$pwd_md5 = md5(md5($this->admin_pwd).$seed);
		
		$data_array = array();
		
		$url = $this->base_url."/interface/client/ClientOffline?enterpriseId=".$this->enterpriseId."&userName=".$this->admin_name."&pwd=".$pwd_md5."&seed=".$seed."&cno=".$call_id;
		
		$mod_ext = new Sys_Extensions();
		$fb = $mod_ext->Broadcast($url, $data_array, 1, 0);
		
		return $fb;
	}
}